package com.masterclient.app.widget.recyclerhelp;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.eoner.baselibrary.utils.DensityUtil;

public class AdapterMeasureHelper {
    // 卡片的间距
    private int mPagePadding = 16;
    // 左右卡片显示的宽度
    private int mCardWidth = 12;

    public void onCreateViewHolder(Context context, View itemView, int position) {
        RecyclerView.LayoutParams lp = (RecyclerView.LayoutParams) itemView.getLayoutParams();

        if (position == 0) {
            int width = DensityUtil.dip2px(mPagePadding/2+mCardWidth);
            lp.width = DensityUtil.getScreenWidth(context) -width;
            itemView.setPadding(DensityUtil.dip2px(mPagePadding + mCardWidth),
                    0, DensityUtil.dip2px(mPagePadding)/2, 0);
        } else if (position == -1) {
            int width = DensityUtil.dip2px(mPagePadding/2+mCardWidth);
            lp.width = DensityUtil.getScreenWidth(context) -width;
            itemView.setPadding(DensityUtil.dip2px(mPagePadding) / 2,
                    0, DensityUtil.dip2px(mPagePadding + mCardWidth), 0);
        } else {
            lp.width = DensityUtil.getScreenWidth(context) -2*DensityUtil.dip2px(mCardWidth)
                    -DensityUtil.dip2px(mPagePadding);
            itemView.setPadding(DensityUtil.dip2px(mPagePadding) / 2,
                    0, DensityUtil.dip2px(mPagePadding) / 2, 0);
        }

        itemView.setLayoutParams(lp);

    }

    public void setPagePadding(int pagePadding) {
        mPagePadding = pagePadding;
    }

    public void setmCardWidth(int mCardWidth) {
        this.mCardWidth = mCardWidth;
    }
}
